package cn.amoqi.springbootasync;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @Description:
 * @author: zhuiFeng
 * @date: 2021年06月03日 15:19
 */
@Service
@Slf4j
public class IndexService {

    /**
     * 异步调用要在不同的类中才生效
     * 返回的为void
     */
    @Async
    public void async(){
        log.info("10s后进行");
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info("我已经执行完成耗时操作");
    }
}
